package com.github.appintro.example.ui;

import com.github.appintro.utile.ResUtil;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;
import ohos.app.Context;

import java.util.List;

class IntroAdapter extends EasyProvider<IntroEntry> {
    private Context context;

    public IntroAdapter(Context context, List<IntroEntry> data, int mLayoutId) {
        super(context, data, mLayoutId);
        this.context = context;
    }

    @Override
    protected void bind(EasyProvider.ViewHolder holder, IntroEntry introEntry, int position) {
        holder.setText(ResourceTable.Id_item_title, ResUtil.getString(context, introEntry.getTitle()));
        holder.setText(ResourceTable.Id_item_description, ResUtil.getString(context, introEntry.getDescription()));
        holder.getView(ResourceTable.Id_item_button).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent intent = new Intent();
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName("com.github.appintro.example.ui")
                        .withAbilityName(introEntry.getActivityClass().getName())
                        .build();
                intent.setOperation(operation);
                context.startAbility(intent, 999);
            }
        });
    }
}
